<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="startDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="微信名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入微信名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信昵称" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入微信昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡A" prop="carda">
        <el-input
          v-model="queryParams.carda"
          placeholder="请输入打卡A"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡B" prop="cardb">
        <el-input
          v-model="queryParams.cardb"
          placeholder="请输入打卡B"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡C" prop="cardc">
        <el-input
          v-model="queryParams.cardc"
          placeholder="请输入打卡C"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡D" prop="cardd">
        <el-input
          v-model="queryParams.cardd"
          placeholder="请输入打卡D"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡E" prop="carde">
        <el-input
          v-model="queryParams.carde"
          placeholder="请输入打卡E"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡F" prop="cardf">
        <el-input
          v-model="queryParams.cardf"
          placeholder="请输入打卡F"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡G" prop="cardg">
        <el-input
          v-model="queryParams.cardg"
          placeholder="请输入打卡G"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡H" prop="cardh">
        <el-input
          v-model="queryParams.cardh"
          placeholder="请输入打卡H"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡I" prop="cardi">
        <el-input
          v-model="queryParams.cardi"
          placeholder="请输入打卡I"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡J" prop="cardj">
        <el-input
          v-model="queryParams.cardj"
          placeholder="请输入打卡J"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡k" prop="cardk">
        <el-input
          v-model="queryParams.cardk"
          placeholder="请输入打卡k"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡L" prop="cardl">
        <el-input
          v-model="queryParams.cardl"
          placeholder="请输入打卡L"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡M" prop="cardm">
        <el-input
          v-model="queryParams.cardm"
          placeholder="请输入打卡M"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡N" prop="cardn">
        <el-input
          v-model="queryParams.cardn"
          placeholder="请输入打卡N"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡O" prop="cardo">
        <el-input
          v-model="queryParams.cardo"
          placeholder="请输入打卡O"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡A描述" prop="cardaDesc">
        <el-input
          v-model="queryParams.cardaDesc"
          placeholder="请输入打卡A描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡B描述" prop="cardbDesc">
        <el-input
          v-model="queryParams.cardbDesc"
          placeholder="请输入打卡B描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡C描述" prop="cardcDesc">
        <el-input
          v-model="queryParams.cardcDesc"
          placeholder="请输入打卡C描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡D描述" prop="carddDesc">
        <el-input
          v-model="queryParams.carddDesc"
          placeholder="请输入打卡D描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡E描述" prop="cardeDesc">
        <el-input
          v-model="queryParams.cardeDesc"
          placeholder="请输入打卡E描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡F描述" prop="cardfDesc">
        <el-input
          v-model="queryParams.cardfDesc"
          placeholder="请输入打卡F描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡G描述" prop="cardgDesc">
        <el-input
          v-model="queryParams.cardgDesc"
          placeholder="请输入打卡G描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡H描述" prop="cardhDesc">
        <el-input
          v-model="queryParams.cardhDesc"
          placeholder="请输入打卡H描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡I描述" prop="cardiDesc">
        <el-input
          v-model="queryParams.cardiDesc"
          placeholder="请输入打卡I描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡J描述" prop="cardjDesc">
        <el-input
          v-model="queryParams.cardjDesc"
          placeholder="请输入打卡J描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡K描述" prop="cardkDesc">
        <el-input
          v-model="queryParams.cardkDesc"
          placeholder="请输入打卡K描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡L描述" prop="cardlDesc">
        <el-input
          v-model="queryParams.cardlDesc"
          placeholder="请输入打卡L描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡M描述" prop="cardmDesc">
        <el-input
          v-model="queryParams.cardmDesc"
          placeholder="请输入打卡M描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡N描述" prop="cardnDesc">
        <el-input
          v-model="queryParams.cardnDesc"
          placeholder="请输入打卡N描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打卡O描述" prop="cardoDesc">
        <el-input
          v-model="queryParams.cardoDesc"
          placeholder="请输入打卡O描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注A" prop="remarka">
        <el-input
          v-model="queryParams.remarka"
          placeholder="请输入备注A"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注B" prop="remarkb">
        <el-input
          v-model="queryParams.remarkb"
          placeholder="请输入备注B"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:record:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:record:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:record:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:record:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序列号" align="center" prop="id" />
      <el-table-column label="日期" align="center" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="微信名称" align="center" prop="name" />
      <el-table-column label="微信昵称" align="center" prop="nickname" />
      <el-table-column label="打卡A" align="center" prop="carda" />
      <el-table-column label="打卡B" align="center" prop="cardb" />
      <el-table-column label="打卡C" align="center" prop="cardc" />
      <el-table-column label="打卡D" align="center" prop="cardd" />
      <el-table-column label="打卡E" align="center" prop="carde" />
      <el-table-column label="打卡F" align="center" prop="cardf" />
      <el-table-column label="打卡G" align="center" prop="cardg" />
      <el-table-column label="打卡H" align="center" prop="cardh" />
      <el-table-column label="打卡I" align="center" prop="cardi" />
      <el-table-column label="打卡J" align="center" prop="cardj" />
      <el-table-column label="打卡k" align="center" prop="cardk" />
      <el-table-column label="打卡L" align="center" prop="cardl" />
      <el-table-column label="打卡M" align="center" prop="cardm" />
      <el-table-column label="打卡N" align="center" prop="cardn" />
      <el-table-column label="打卡O" align="center" prop="cardo" />
      <el-table-column label="打卡A描述" align="center" prop="cardaDesc" />
      <el-table-column label="打卡B描述" align="center" prop="cardbDesc" />
      <el-table-column label="打卡C描述" align="center" prop="cardcDesc" />
      <el-table-column label="打卡D描述" align="center" prop="carddDesc" />
      <el-table-column label="打卡E描述" align="center" prop="cardeDesc" />
      <el-table-column label="打卡F描述" align="center" prop="cardfDesc" />
      <el-table-column label="打卡G描述" align="center" prop="cardgDesc" />
      <el-table-column label="打卡H描述" align="center" prop="cardhDesc" />
      <el-table-column label="打卡I描述" align="center" prop="cardiDesc" />
      <el-table-column label="打卡J描述" align="center" prop="cardjDesc" />
      <el-table-column label="打卡K描述" align="center" prop="cardkDesc" />
      <el-table-column label="打卡L描述" align="center" prop="cardlDesc" />
      <el-table-column label="打卡M描述" align="center" prop="cardmDesc" />
      <el-table-column label="打卡N描述" align="center" prop="cardnDesc" />
      <el-table-column label="打卡O描述" align="center" prop="cardoDesc" />
      <el-table-column label="备注A" align="center" prop="remarka" />
      <el-table-column label="备注B" align="center" prop="remarkb" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:record:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:record:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改打卡记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期" prop="startDate">
          <el-date-picker clearable size="small"
            v-model="form.startDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="微信名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入微信名称" />
        </el-form-item>
        <el-form-item label="微信昵称" prop="nickname">
          <el-input v-model="form.nickname" placeholder="请输入微信昵称" />
        </el-form-item>
        <el-form-item label="打卡A" prop="carda">
          <el-input v-model="form.carda" placeholder="请输入打卡A" />
        </el-form-item>
        <el-form-item label="打卡B" prop="cardb">
          <el-input v-model="form.cardb" placeholder="请输入打卡B" />
        </el-form-item>
        <el-form-item label="打卡C" prop="cardc">
          <el-input v-model="form.cardc" placeholder="请输入打卡C" />
        </el-form-item>
        <el-form-item label="打卡D" prop="cardd">
          <el-input v-model="form.cardd" placeholder="请输入打卡D" />
        </el-form-item>
        <el-form-item label="打卡E" prop="carde">
          <el-input v-model="form.carde" placeholder="请输入打卡E" />
        </el-form-item>
        <el-form-item label="打卡F" prop="cardf">
          <el-input v-model="form.cardf" placeholder="请输入打卡F" />
        </el-form-item>
        <el-form-item label="打卡G" prop="cardg">
          <el-input v-model="form.cardg" placeholder="请输入打卡G" />
        </el-form-item>
        <el-form-item label="打卡H" prop="cardh">
          <el-input v-model="form.cardh" placeholder="请输入打卡H" />
        </el-form-item>
        <el-form-item label="打卡I" prop="cardi">
          <el-input v-model="form.cardi" placeholder="请输入打卡I" />
        </el-form-item>
        <el-form-item label="打卡J" prop="cardj">
          <el-input v-model="form.cardj" placeholder="请输入打卡J" />
        </el-form-item>
        <el-form-item label="打卡k" prop="cardk">
          <el-input v-model="form.cardk" placeholder="请输入打卡k" />
        </el-form-item>
        <el-form-item label="打卡L" prop="cardl">
          <el-input v-model="form.cardl" placeholder="请输入打卡L" />
        </el-form-item>
        <el-form-item label="打卡M" prop="cardm">
          <el-input v-model="form.cardm" placeholder="请输入打卡M" />
        </el-form-item>
        <el-form-item label="打卡N" prop="cardn">
          <el-input v-model="form.cardn" placeholder="请输入打卡N" />
        </el-form-item>
        <el-form-item label="打卡O" prop="cardo">
          <el-input v-model="form.cardo" placeholder="请输入打卡O" />
        </el-form-item>
        <el-form-item label="打卡A描述" prop="cardaDesc">
          <el-input v-model="form.cardaDesc" placeholder="请输入打卡A描述" />
        </el-form-item>
        <el-form-item label="打卡B描述" prop="cardbDesc">
          <el-input v-model="form.cardbDesc" placeholder="请输入打卡B描述" />
        </el-form-item>
        <el-form-item label="打卡C描述" prop="cardcDesc">
          <el-input v-model="form.cardcDesc" placeholder="请输入打卡C描述" />
        </el-form-item>
        <el-form-item label="打卡D描述" prop="carddDesc">
          <el-input v-model="form.carddDesc" placeholder="请输入打卡D描述" />
        </el-form-item>
        <el-form-item label="打卡E描述" prop="cardeDesc">
          <el-input v-model="form.cardeDesc" placeholder="请输入打卡E描述" />
        </el-form-item>
        <el-form-item label="打卡F描述" prop="cardfDesc">
          <el-input v-model="form.cardfDesc" placeholder="请输入打卡F描述" />
        </el-form-item>
        <el-form-item label="打卡G描述" prop="cardgDesc">
          <el-input v-model="form.cardgDesc" placeholder="请输入打卡G描述" />
        </el-form-item>
        <el-form-item label="打卡H描述" prop="cardhDesc">
          <el-input v-model="form.cardhDesc" placeholder="请输入打卡H描述" />
        </el-form-item>
        <el-form-item label="打卡I描述" prop="cardiDesc">
          <el-input v-model="form.cardiDesc" placeholder="请输入打卡I描述" />
        </el-form-item>
        <el-form-item label="打卡J描述" prop="cardjDesc">
          <el-input v-model="form.cardjDesc" placeholder="请输入打卡J描述" />
        </el-form-item>
        <el-form-item label="打卡K描述" prop="cardkDesc">
          <el-input v-model="form.cardkDesc" placeholder="请输入打卡K描述" />
        </el-form-item>
        <el-form-item label="打卡L描述" prop="cardlDesc">
          <el-input v-model="form.cardlDesc" placeholder="请输入打卡L描述" />
        </el-form-item>
        <el-form-item label="打卡M描述" prop="cardmDesc">
          <el-input v-model="form.cardmDesc" placeholder="请输入打卡M描述" />
        </el-form-item>
        <el-form-item label="打卡N描述" prop="cardnDesc">
          <el-input v-model="form.cardnDesc" placeholder="请输入打卡N描述" />
        </el-form-item>
        <el-form-item label="打卡O描述" prop="cardoDesc">
          <el-input v-model="form.cardoDesc" placeholder="请输入打卡O描述" />
        </el-form-item>
        <el-form-item label="备注A" prop="remarka">
          <el-input v-model="form.remarka" placeholder="请输入备注A" />
        </el-form-item>
        <el-form-item label="备注B" prop="remarkb">
          <el-input v-model="form.remarkb" placeholder="请输入备注B" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/system/record";

export default {
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 打卡记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startDate: null,
        name: null,
        nickname: null,
        carda: null,
        cardb: null,
        cardc: null,
        cardd: null,
        carde: null,
        cardf: null,
        cardg: null,
        cardh: null,
        cardi: null,
        cardj: null,
        cardk: null,
        cardl: null,
        cardm: null,
        cardn: null,
        cardo: null,
        cardaDesc: null,
        cardbDesc: null,
        cardcDesc: null,
        carddDesc: null,
        cardeDesc: null,
        cardfDesc: null,
        cardgDesc: null,
        cardhDesc: null,
        cardiDesc: null,
        cardjDesc: null,
        cardkDesc: null,
        cardlDesc: null,
        cardmDesc: null,
        cardnDesc: null,
        cardoDesc: null,
        remarka: null,
        remarkb: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询打卡记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        startDate: null,
        name: null,
        nickname: null,
        carda: null,
        cardb: null,
        cardc: null,
        cardd: null,
        carde: null,
        cardf: null,
        cardg: null,
        cardh: null,
        cardi: null,
        cardj: null,
        cardk: null,
        cardl: null,
        cardm: null,
        cardn: null,
        cardo: null,
        cardaDesc: null,
        cardbDesc: null,
        cardcDesc: null,
        carddDesc: null,
        cardeDesc: null,
        cardfDesc: null,
        cardgDesc: null,
        cardhDesc: null,
        cardiDesc: null,
        cardjDesc: null,
        cardkDesc: null,
        cardlDesc: null,
        cardmDesc: null,
        cardnDesc: null,
        cardoDesc: null,
        remarka: null,
        remarkb: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加打卡记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改打卡记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除打卡记录编号为"' + ids + '"的数据项？').then(function() {
        return delRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/record/export', {
        ...this.queryParams
      }, `record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
